package com.yanqu.road.server.cmd.activity.stronghold.eliminate;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.stronghold.StrongholdEliminateDefendPatrons;
import com.yanqu.road.logic.pb.PatronsPb;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.pb.StrongholdPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.math.BigInteger;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Cmd(code = GameProtocol.S_STRONGHOLD_WAR_ELIMINATION_MEMBER_DEFEND_PATRONS, desc = "获取联盟防守门客列表")
public class GetEliminateUnionDefendPatronsListCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = StrongholdActivityMgr.getOpenActivityInfo();
       /* StrongholdWarProto.UnionStrongholdDefendRespMsg.Builder resp = StrongholdWarProto.UnionStrongholdDefendRespMsg.newBuilder();
        if (activityInfo != null) {
            int activityId = activityInfo.getActivityId();
            String unionUid = player.getUserInfo().getUnionUid();
            List<StrongholdEliminateDefendPatrons> defendList = StrongholdWarMgr.getEliminateDefendList(activityId, unionUid);
            resp.setStarLv(StrongholdWarMgr.getUnionBaseLv(activityId, unionUid));
            BigInteger baseBlood = BigInteger.ZERO;

            Set<Long> battleMemberId = new HashSet<>();
            for (StrongholdEliminateDefendPatrons patrons : defendList) {
                StrongholdWarProto.UnionMemberDispatchPatronsTempMsg.Builder tempMsg = StrongholdPb.parseUnionMemberDispatchPatronsTempMsg(patrons);
                resp.addMemberData(tempMsg);
                baseBlood = baseBlood.add(patrons.getTotalBlood());
                battleMemberId.add(patrons.getUserId());
            }
            resp.setBattleNum(battleMemberId.size());
            //千分比
            int hpAdd = StrongholdWarMgr.getHpAdd(activityInfo.getActivityId(), unionUid);
            BigInteger totalBlood = baseBlood.add(baseBlood.multiply(BigInteger.valueOf(hpAdd)).divide(BigInteger.valueOf(1000)));
            resp.setBaseBlood(baseBlood.longValue());
            resp.setTotalBlood(totalBlood.longValue());
            resp.setHpAdd(hpAdd);
            player.sendChannelPacket(ClientProtocol.U_STRONGHOLD_WAR_ELIMINATION_MEMBER_DEFEND_PATRONS, resp);
        }*/
        StrongholdWarCrossProto.StrongholdCrossDefendPatronsReqMsg.Builder req = StrongholdWarCrossProto.StrongholdCrossDefendPatronsReqMsg.newBuilder();
        String unionUid = player.getUserInfo().getUnionUid();
        req.setActivityId(activityInfo.getActivityId());
        req.setUnionId(unionUid);
        player.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_STRONGHOLD_ELIMINATION_MEMBER_DEFEND_PATRONS, req, req.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
